<?php
defined('OA_LIB_PATH') || define('OA_LIB_PATH', '/opt/op/OALib');

require_once 'PHPUnit/Framework.php';
require_once 'Log.php';
require_once OA_LIB_PATH . '/util/model/OpDbModel.php';

class OpDbModelTest extends PHPUnit_Framework_TestCase
{
    private $_logger;
    private $_model;
    
    protected function setUp()
    {
        $logger = Log::factory('console');
        $logger->setMask(Log::MAX(PEAR_LOG_DEBUG));
        $this->_logger = $logger;
        $this->_model = new OpDbModel(array(
            'host' => '10.129.148.6',
            'user' => 'open',
            'pass' => 'open',
            'name' => 'oa_web'
        ), $logger);
    }
    
    protected function tearDown()
    {
        
    }
    
    public function testQuery()
    {
        $sql = "select * from role where name like 'app.%'";
        $result = $this->_model->query($sql);
        $this->assertTrue(is_array($result) && !empty($result));
        $sql = "select * from role where name like 'no.%'";
        $result = $this->_model->query($sql);
        $this->assertTrue(is_array($result) && empty($result));
    }
    
    public function testQueryRow()
    {
        $sql = "select * from role where name='app.admin'";
        $result = $this->_model->queryRow($sql);
        $this->assertTrue(is_array($result));
        $sql = "select * from role where name='app.no'";
        $result = $this->_model->queryRow($sql);
        $this->assertTrue(is_null($result));
    }
}
